let app = {
    init: function (receive,init) {
        document.addEventListener('astilectron-ready', function () {
            app.listen(receive)
            try {
                init();
            } catch (e) {
            }
        })
    },
    goFunc: function (name, param) {
        app.sendMessage("go_func", {name: name, param: param})
    },
    sendMessage: function (name, payload, callback) {
        astilectron.sendMessage({name: name, payload: payload}, callback)
    },
    listen: function (receive) {
        astilectron.onMessage(function (message) {
            switch (message.name) {
                case "go_error" :
                    console.error("GO_ERROR：" + message.payload);
                    break;
                case "go_log" :
                    console.log("GO_LOG：" + message.payload)
                    break;
                case "js_func" :
                    const data = JSON.parse(message.payload);
                    eval(data.name + '(data.param)');
                    break;
                default:
                    try {
                        receive(message);
                    } catch (e) {
                    }
            }
        });
    },
    html: function (tage, content) {
        var structStr = tage.substr(0, 1)
        var dTages = tage.slice(1);
        switch (structStr) {
            case ".":
                tagArr = document.getElementsByClassName(dTages)
                for (keys in tagArr) {
                    tagArr[keys].innerHTML = content;
                }
                break
            case "#":
                document.getElementById(dTages).innerHTML = content
                break
            default:
                tagArr = document.getElementsByTagName(structStr)
                for (keys in tagArr) {
                    tagArr[keys].innerHTML = content;
                }
        }
    }
};